/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.purpose.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.koron.purpose.bean.SafetyDirectorAssessmentBean;
import com.koron.purpose.domain.SafetyDirectorAssessment;

public interface SafetyDirectorAssessmentMapper {
	
	@Insert("insert into safety_director_assessment(id,add_user,add_time,update_user,update_time,add_user_name,update_user_name,"
			+ "staff_name,staff_code,corp_code,dept_code,dept_name,corp_type,assessment_type,month,basic_score,since_score,fstatusflag,note,"
			+ "assessment_score,flag_number,flag_now,score_staffs )"
			+ "values(#{id},#{addUser},#{addTime},#{updateUser},#{updateTime},#{addUserName},#{updateUserName},"
			+ "#{staffName},#{staffCode},#{corpCode},#{deptCode},#{deptName},#{corpType},#{assessmentType},#{month},#{basicScore},#{sinceScore},#{fstatusflag},#{note},"
			+ "#{assessmentScore},#{flagNumber},#{flagNow},#{scoreStaffs})")
	int insert(SafetyDirectorAssessment bean);
	
	@Update("update safety_director_assessment set update_user=#{updateUser},update_time=#{updateTime},update_user_name=#{updateUserName},"
			+ "staff_name=#{staffName},staff_code=#{staffCode},dept_code=#{deptCode},dept_name=#{deptName},corp_type=#{corpType},assessment_type=#{assessmentType},"
			+ "month=#{month},since_score=#{sinceScore},note=#{note},assessment_score=#{assessmentScore},"
			+ "flag_number=#{flagNumber} where id=#{id}")
	int update(SafetyDirectorAssessment bean);
	
	@Delete("delete from safety_director_assessment where id=#{id}")
	int delete(@Param("id")String id);
	
	@Select("select * from safety_director_assessment where id=#{id}")
	SafetyDirectorAssessmentBean queryById(@Param("id")String id);
	
	@Select("<script>"
			+ "select count(*) from safety_director_assessment where 1=1 "
			+ "<if test='corpCode!=null'> and corp_code=#{corpCode} </if>"
			+ "<if test='addUser!=null'> and (add_user=#{addUser} or locate(#{addUser},score_staffs)>0 )</if>"
			+ "<if test='month!=null'> and month=#{month} </if>"
			+ "<if test='corpType!=null'> and corp_type=#{corpType} </if>"
			+ "<if test='staffName!=null'> and staff_name like #{staffName} </if>"
			+ "<if test='assessmentType!=null'> and assessment_type=#{assessmentType} </if>"
			+ "<if test='fstatusflag!=null'> and fstatusflag=#{fstatusflag} </if>"
			+ "</script>")
	int count(@Param("corpCode")String corpCode,@Param("addUser")String addUser,@Param("month")String month,
			@Param("corpType") Integer corpType,@Param("staffName")String staffName
			,@Param("assessmentType")Integer assessmentType,@Param("fstatusflag")Integer fstatusflag);
	
	
	@Select("<script>"
			+ "select * from safety_director_assessment where 1=1 "
			+ "<if test='corpCode!=null'> and corp_code=#{corpCode} </if>"
			+ "<if test='addUser!=null'> and (add_user=#{addUser} or locate(#{addUser},score_staffs)>0 )</if>"
			+ "<if test='month!=null'> and month=#{month} </if>"
			+ "<if test='corpType!=null'> and corp_type=#{corpType} </if>"
			+ "<if test='staffName!=null'> and staff_name like #{staffName} </if>"
			+ "<if test='assessmentType!=null'> and assessment_type=#{assessmentType} </if>"
			+ "<if test='fstatusflag!=null'> and fstatusflag=#{fstatusflag} </if>"
			+ "order by month desc "
			+ "<if test='start!=null'> limit #{start},#{row} </if>"
			+ "</script>")
	List<SafetyDirectorAssessmentBean> list(@Param("corpCode")String corpCode,@Param("addUser")String addUser,
			@Param("month")String month,@Param("corpType") Integer corpType,@Param("staffName")String staffName,
			@Param("assessmentType")Integer assessmentType,@Param("fstatusflag")Integer fstatusflag,
			@Param("start")Integer start,@Param("row")Integer row);
	
	@Update("update safety_director_assessment set fstatusflag=#{fstatusflag},flag_now=#{flagNow},"
			+ "assessment_score=#{assessmentScore},score_staffs=#{scoreStaffs} where id=#{id}")
	int updateScore(SafetyDirectorAssessment bean);
}
